﻿using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media.Animation;
using DW.IntelligenceSource.GUI.Map;
using System.Linq;
namespace DW.IntelligenceSource.GUI.MapView {
  public enum MapAnimations{CollapseMap, nullValue}

  public partial class MapView : IMap {
    public virtual double PanelTop {
      get { return Canvas.GetTop(MapRoot); }
      set { Canvas.SetTop(MapRoot, value); }
    }
    public virtual List<Country> SelectableCountries { get; set; }
    public MapAnimations LastAnimation{ get; set;}
    public virtual double PanelLeft {
      get { return Canvas.GetTop(MapRoot); }
      set { Canvas.SetTop(MapRoot, value); }
    }

    public static readonly DependencyProperty ZoomProperty
      = DependencyProperty.Register(
        "Zoom",
        typeof (double),
        typeof (MapView));

    public double Zoom{
      get { return (double) GetValue(ZoomProperty); }
      set { SetValue(ZoomProperty, value); }
    }

    public Storyboard ZoomToCountry{
      get { return FindResource("ZoomToCountry") as Storyboard;}
    }
      public Button ResetButtonPublic{ get; private set;}

    public MapView() {
      InitializeComponent();
      MapRoot = Root;
      layoutGrid = LayoutGrid;
      LastAnimation = MapAnimations.nullValue;
      ResetButtonPublic = ResetButton;
      wireupEvents();
    }

    public delegate void MapMouseClickEventHandler(object sender, Point clickPoint);
    public delegate void MapMouseMoveEventHandler(object sender, Point DragPoint);
    public delegate void MapMouseUpEventHandler(object sender);
    public delegate void MapMouseWheelEventHandler(object sender, object source, int wheelDelta);
    public delegate void MapButtonClickHandler(object sender);
    public delegate void MapEventDelegate();
    public delegate void MapAnimationDelegate(bool reverse);
    public event MapButtonClickHandler MapResetButtonClick;
    public event MapEventDelegate MapOnRender;
    public event MapAnimationDelegate ZoomToCountryCalled;
    public void AnimateRight(bool reverse){
      if(ZoomToCountryCalled != null){
        ZoomToCountryCalled(reverse);
      }
    }

    private void wireupEvents(){
      ResetButton.Click += ((sender, args) => MapResetButtonClick(args.OriginalSource));
      
    }


    public virtual Canvas MapRoot { get; private set; }
    public virtual Grid layoutGrid { get; private set; }
    public virtual MapController.MapMouseWheelEventHandler ControllerMapMouseWheel { get; set; }
    public virtual MapController.MapMouseClickEventHandler ControllerMapMouseClick { get; set; }
    public virtual MapController.MapMouseMoveEventHandler ControllerMapMouseMove { get; set; }
    public virtual MapController.MapMouseUpEventHandler ControllerMapMouseUp { get; set; }


    protected override void OnRender(System.Windows.Media.DrawingContext drawingContext) {
      base.OnRender(drawingContext);
      if(MapOnRender != null){
        MapOnRender();
      }
    }

    public RoutedEventHandler ResetButtonClick {
      get { return null; }
      set {
        ResetButton.Click += value;
      }
    }

    public MouseWheelEventHandler MapMouseWheel {
      set {
        LayoutGrid.MouseWheel += value;
      }
    }

    public MouseEventHandler MapMouseMove {
      set {
        LayoutGrid.MouseMove += value;
      }
    }

    public MouseButtonEventHandler MapMouseLeftButtonDown {
      set {
        LayoutGrid.MouseLeftButtonDown += value;
      }
    }

    public MouseButtonEventHandler MapMouseLeftButtonUp {
      set {
        LayoutGrid.MouseLeftButtonUp += value;
      }
    }

    private void UserControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) {

    }



  }
}